<template>
    <div id="app">
        <span>App</span>
        <lego-form :initial-values="formValues">
            <div v-if="inputShow">
                <input-view v-bind="addressProps" />
            </div>
            <submit />
        </lego-form>
    </div>
</template>

<script>
import spec from './spec.json';
import userData from './data.json';
import {createFormModel} from '../src/index';
import {defineComponent, ref} from 'vue';
import LegoForm from '../src/components/Form.vue';
import InputView from './InputView.vue';
import Submit from './Submit.vue';
import {formValues, addressProps} from './data';
import {getPreviewValue} from '../src/util/previewValue';

export default defineComponent({
    name: 'App',
    components: {
        LegoForm,
        InputView,
        Submit
    },
    setup() {
        const formPreviewValues = getPreviewValue(spec, {}, '', userData);
        const inputShow = ref(true);
        const dashboardShow = ref(true);
        const onDashboardClick = () => {
            inputShow.value = false;
        };
        const onLogoffDashboard = () => {
            dashboardShow.value = false;
        };
        const modelTree = createFormModel(spec, userData);

        return {
            onDashboardClick,
            onLogoffDashboard,
            inputShow,
            dashboardShow,
            modelTree,
            addressProps,
            formValues,
            formPreviewValues
        };
    }
});
</script>

<style>
#app {
    font-family: Avenir, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    color: #2c3e50;
    margin-top: 60px;
}
</style>
